﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MediaCenterCommander.RemoteInterfaces;
using System.IO;
using System.Diagnostics;

namespace MediaCenterCommander.UserAgent.Services
{
    public class MediaCenterCommanderUserAgent : MarshalByRefObject, IMediaCenterCommanderUserAgent    
    {
        public override object InitializeLifetimeService()
        {
            return null;
        }

        public void LaunchMediaCenterIfNotRunning()
        {
            string expectedMediaCenterExe = System.IO.Path.GetDirectoryName(Environment.SystemDirectory) + @"\ehome\ehshell.exe";

            if (!File.Exists(expectedMediaCenterExe))
            {
                throw new Exception("Media Center not found at " + expectedMediaCenterExe);
            }

            Process[] processList = Process.GetProcessesByName("ehshell");
            if (processList == null || processList.Length == 0)
            {
                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName = expectedMediaCenterExe;
                psi.WindowStyle = ProcessWindowStyle.Maximized;
                psi.Arguments = "/nostartupanimation";
                Process.Start(psi);
            }
        }
    }
}
